<?php
/**	
*	FILENAME: 		/server_app/authenticate_wildcard.php
*	DESCRIPTION:	This script creates a valid JSON response after authenticating a user to the Office of the Wildcard website.
*	AUTHOR:			Casey Burkhardt
*	VERSION:		1.0.0
*	LAST MODIFIED:	02/14/10
**/

require_once($_SERVER['DOCUMENT_ROOT'] . "/libraries/wildcard.php");
require_once($_SERVER['DOCUMENT_ROOT'] . "/libraries/functions.php");

enforceSSL();

$userName = $_POST["username"];
$password = $_POST["password"];

if (strlen($userName) == 0 || strlen($password) == 0) {
	// Inproper Data
	$response["response_type"] = "error";
	$response["error_desc"] = "Username or Password Left Blank.";
	echo(json_encode($response));
} else if (getWildcardSession($userName, $password) !== FALSE) {
	// Authenticated
	$response["response_type"] = "success";
	echo(json_encode($response));
} else {
	// Not Authenticaed
	$response["response_type"] = "error";
	$response["error_desc"] = "Invalid Username and Password.";
	echo(json_encode($response));
}